package eco2automotive.data;

import java.util.HashMap;
import java.io.*;
 /**  
  * This object serializable contains a HashMap to access and storage the
  * error codes
  * @version 1.0
  * @autor Fco. Javier Sánchez Esparza
  *
  */ 
public class HashErrorCode implements Serializable{
   HashMap table;
   /**
    * Default constructor, create a new HashMap 
    */
   public HashErrorCode(){table = new HashMap(); }
     /** 
     * Constructor
     * @param h - HashMap to assign
    */
   public HashErrorCode(HashMap h){
       table = h;
   }   
   /**
    * This method return the object HasMap 
    * @return table - the HasMap
    */
   public HashMap getHashErrorCode(){
       return this.table;
   }
   
    /** 
     * Insert a new ErrorCode
     * @param error - ErrorCode to add
    */
   public void insertError(ErrorCode error){
	String key = new String();        
	key=error.getCode();
        System.out.println("KEY ERROR in HASH "+key);
        if (!(table.containsKey(key)))
        {
	Object value = table.put(key,error);     
            	}
	else
	{	                                                       
              System.out.println("HASH_Insert_KeyDuplicated "+key);
	}
	}
   
    /** 
    * Returns a ErrorCode by code
     * @param code - Code to find in the HashMap
    *  @return ErroCode or null if not exists 
    */
   public ErrorCode getErrorCode(String code){
	 Object error = table.get(code);
	 if (error==null)
	 	{                 
                return null;
	 	}	
	 return (ErrorCode) error;
	} 
   
    /** 
     * Delete a ErrorCode by code from the HashMap
     * @param code - The code to delete
    */
   public void deleteErrorCode(String code){
	if (!(table.containsKey(code))){				
            System.out.println("HASH_DeleteCode_notFound "+code);		
			}
			else	
			{	 
				Object value = table.remove(code);				
			}
	} 
   
}
